@isTest
private class TestQuickLeadRequest_WS {
	
	/****Condition for finding record in Account****/
	static testMethod void duplicateAccount(){
		/*Creating Test Database*/
		Program__c programName = TestDatabaseCMS.createProgramForTesting();
		Account testAccount = TestDatabaseCMS.createAccountForTesting();
		
		/*Testing*/
		test.startTest();
    	String duplicateAccount = QuickLeadRequest_WS.createLeadOrUpdateAccount('CreateCase','TestUser','abcd1@ddd.com','Arizona','Bachelor of Science in Accounting','03/2013','(234) 343-2345', 'QuickApp', 'Typical','RFI Section 1');
		test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(duplicateAccount.contains('Success'));
	}

	/****Condition for finding record in Lead****/
	static testMethod void duplicateLead(){
		/*Creating Test Database*/
		Lead testLead = TestDatabaseCMS.createLeadForTesting();
		
		/*Testing*/
		test.startTest();
    	String duplicateLead = QuickLeadRequest_WS.createLeadOrUpdateAccount('CreateCase','TestLead','ssss@yyyy.com','AZ','Bachelor of Science in Accounting','03/2013','(234) 343-2345', 'QuickApp', 'Typical','RFI Section 1');
		test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(duplicateLead.contains('Success'));
	}

	/*Condition for not finding record in Salesforce*/
	static testMethod void noDuplicate(){
		/*Creating Test Database*/
		Program__c programName = TestDatabaseCMS.createProgramForTesting();
		
		/*Testing*/
		test.startTest();
    	String noDuplicate = QuickLeadRequest_WS.createLeadOrUpdateAccount('CreateCasess','TestUsesr','abcd1@ddds.com','AZ','Bachelor of Science in Accounting','03/2013','(234) 343-2345', 'QuickApp', 'Typical','RFI Section 1');
		test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(noDuplicate.contains('Success'));
	}

	/*Error Condition - Missing Mandatory field*/
	static testMethod void errorMissingMandatoryField(){	
		/*Testing*/
		test.startTest();
    	String errorMissingMandatoryField = QuickLeadRequest_WS.createLeadOrUpdateAccount('CreateCasess','','abcd1@ddds.com','Arizona','Bachelor of Science in Accounting','','(234) 343-2345', 'QuickApp', 'Typical','RFI Section 1');
		test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(errorMissingMandatoryField.contains('Failure'));
	}
	
	/*Error Condition - Date Format Error*/
	static testMethod void errorDateFormat(){
		/*Creating Test Database*/
		Lead testLead = TestDatabaseCMS.createLeadForTesting();
		Account testAccount = TestDatabaseCMS.createAccountForTesting();
		
		/*Testing*/
		test.startTest();
    	String errorDateFormat = QuickLeadRequest_WS.createLeadOrUpdateAccount('CreateCase','TestUser','abcd1@ddd.com','AZ','Bachelor of Science in Accounting','03-2013','(234) 343-2345', 'QuickApp', 'Typical','RFI Section 1');
    	String errorDateFormat2 = QuickLeadRequest_WS.createLeadOrUpdateAccount('CreaffteCase','TestUser','abcd1@ddd.com','AZ','Bachelor of Science in Accounting','03/-2013','(234) 343-2345', 'QuickApp', 'Typical','RFI Section 1');
    	String errorDateFormat3 = QuickLeadRequest_WS.createLeadOrUpdateAccount('CreateCase','TestLead','ssss@yyyy.com','AZ','Bachelor of Science in Accounting','03/-2013','(234) 343-2345', 'QuickApp', 'Typical','RFI Section 1');
		test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(errorDateFormat.contains('Failure'));
    	System.assert(errorDateFormat2.contains('Failure'));
    	System.assert(errorDateFormat3.contains('Failure'));
	}

	/*Error Condition - Program not found*/
	static testMethod void errorProgram(){
		/*Creating Test Database*/
		Program__c programName = TestDatabaseCMS.createProgramForTesting();
		Account testAccount = TestDatabaseCMS.createAccountForTesting();
		
		/*Testing*/
		test.startTest();
    	String errorProgram = QuickLeadRequest_WS.createLeadOrUpdateAccount('CreateCase','TestUser','abcd1@ddd.com','AZ','Bachelor of arts in Accounting','03/2013','(234) 343-2345', 'QuickApp', 'Typical','RFI Section 1');
		test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(errorProgram.contains('Failure'));
	}
	
	/*Error Condition - Phone Format Error*/
	static testMethod void errorPhoneFormat(){
		/*Creating Test Database*/
		//Lead testLead = TestDatabaseCMS.createLeadForTesting();
		//Account testAccount = TestDatabaseCMS.createAccountForTesting();
		
		/*Testing*/
		test.startTest();
    	String errorPhoneFormat = QuickLeadRequest_WS.createLeadOrUpdateAccount('CreateCase','TestUser','abcd1@ddd.com','AZ','Bachelor of Science in Accounting','03/2013','(234) 343d3-2345', 'QuickApp', 'Typical','RFI Section 1');
		test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(errorPhoneFormat.contains('Failure'));
	}
}